
function Village()
{
    var mStructureArray = new Array();
    var mLumber = 0;
    var mClay = 0;
    var mIron = 0;
    var mLumberPerHour = 0;
    var mClayPerHour = 0;
    var mIronPerHour = 0;
    var mCropPerHour = 0;
    var mCrop = 0;
    var mCropConsumption = 0;
    var mMaximumCropConsumption = 0;

    this.initialize = function()
    {
        this.initializeStructures();
        this.initializeResources();
    }

    this.initializeStructures = function()
    {
        var view = new ResourceMapView();
        structures = view.getStructures();

        for (var i = 0, n = structures.length; i < n; ++i)  {
            this.addStructure(structure);
        }

        view = new BuildingMapView();
        structures = view.getStructures();

        for (var i = 0, n = structures.length; i < n; ++i)  {
            this.addStructure(structure);
        }

        return;
    }

    this.addStructure = function(structure)
    {
        var structureId = structure.getId();

        for (var i = 0, n = mStructureArray.length; i < n; ++i)
        {
            if (mStructureArray[i].getId() == structureId)  {   // then replace with newest version
                mStructureArray[i] = structure;
            }
        }

        mStructureArray.push(structure);

        return;
    }

    this.removeStructure = function(structure)
    {
        var structureId;

        if (structure == undefined)
        {
            mStructureArray = new Array();
            return;
        }

        structureId = structure.getId();

        for (var i = 0, n = mStructureArray.length; i < n; ++i)
        {
            if (mStructureArray[i].getId() == structureId)   // then replace with newest version
            {
                mStructureArray.splice(i, 1);
                return;
            }
        }

        throw "Structure `" + structureId + "` not found.";
    }

    this.getStuctures() = function()
    {
        return this.mStructureArray;
    }
}
